<?php

namespace app\common\model;

use think\Model;

class UserToken extends Model
{
    protected $autoWriteTimestamp = true;
    protected $type = [
        'create_time' => 'integer',
        'update_time' => 'integer',
    ];

    public function user()
    {
        return $this->belongsTo('User');
    }

    //保存token
    public function saveToken($user_id, $token)
    {
        $token_expire_time = time() + 86400 * 30;
        $this->save(['user_id' => $user_id, 'token' => $token, 'token_expire_time' => $token_expire_time]);
    }
}
